﻿<UserControl x:Class="SampleApp.Samples.CompositeCommandsView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:toms="urn:TomsToolbox"
             xmlns:local="clr-namespace:SampleApp"
             xmlns:samples="clr-namespace:SampleApp.Samples"
             d:DataContext="{d:DesignInstance samples:CompositeCommandsViewModel}">
  <StackPanel Margin="10">
    <StackPanel.Resources>
      <DataTemplate DataType="{x:Type toms:CommandSource}">
        <Button Command="{Binding Command}" BorderThickness="0" Margin="1" Padding="2">
          <Image Source="{Binding Icon}" />
        </Button>
      </DataTemplate>
    </StackPanel.Resources>
    <Menu Style="{DynamicResource {x:Static toms:ResourceKeys.CompositeMenuStyle}}" toms:VisualComposition.RegionId="{x:Static local:RegionId.Menu}"/>
    <ToolBar toms:VisualComposition.RegionId="{x:Static local:RegionId.ToolBar}">
      <ToolBar.Resources>
        <ControlTemplate x:Key="ToolBarGroupItemTemplate" TargetType="{x:Type GroupItem}">
          <StackPanel Orientation="Horizontal">
            <Separator Style="{DynamicResource {x:Static ToolBar.SeparatorStyleKey}}"/>
            <ItemsPresenter />
          </StackPanel>
        </ControlTemplate>
        <ControlTemplate x:Key="FirstToolBarGroupItemTemplate" TargetType="{x:Type GroupItem}">
          <ItemsPresenter />
        </ControlTemplate>
        <GroupStyle x:Key ="ToolBarGroupStyle">
          <GroupStyle.ContainerStyle>
            <Style TargetType="GroupItem">
              <Setter Property="Template" Value="{StaticResource ToolBarGroupItemTemplate}"/>
              <Style.Triggers>
                <DataTrigger Binding="{Binding RelativeSource={RelativeSource PreviousData}}" Value="{x:Null}">
                  <Setter Property="Template" Value="{StaticResource FirstToolBarGroupItemTemplate}"/>
                </DataTrigger>
              </Style.Triggers>
            </Style>
          </GroupStyle.ContainerStyle>
          <GroupStyle.Panel>
            <ItemsPanelTemplate>
              <StackPanel Orientation="Horizontal"/>
            </ItemsPanelTemplate>
          </GroupStyle.Panel>
        </GroupStyle>
      </ToolBar.Resources>
      <ToolBar.Style>
        <Style TargetType="ToolBar">
          <Setter Property="toms:StyleBindings.GroupStyle" Value="{StaticResource ToolBarGroupStyle}"/>
          <Setter Property="toms:StyleBindings.GroupDescriptions">
            <Setter.Value>
              <toms:GroupDescriptionCollection>
                <PropertyGroupDescription PropertyName="GroupName"/>
              </toms:GroupDescriptionCollection>
            </Setter.Value>
          </Setter>
          <Setter Property="Template">
            <Setter.Value>
              <ControlTemplate>
                <Border Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}" Padding="2">
                  <ItemsPresenter  />
                </Border>
              </ControlTemplate>
            </Setter.Value>
          </Setter>
          <Setter Property="ItemsPanel">
            <Setter.Value>
              <ItemsPanelTemplate>
                <StackPanel Orientation="Horizontal"/>
              </ItemsPanelTemplate>
            </Setter.Value>
          </Setter>
        </Style>
      </ToolBar.Style>
    </ToolBar>
    <Border Background="Orange" ContextMenu="{toms:CompositeContextMenu RegionId={x:Static local:RegionId.ContextMenu}}">
      <StackPanel Margin="10">
        <TextBlock>
          Sample of composite commands with menu, tool bar and context menu.<LineBreak/>
          <LineBreak/>
          Right-Click to open the context menu.
        </TextBlock>
      </StackPanel>
    </Border>
  </StackPanel>
  <i:Interaction.Behaviors>
    <toms:CommandRoutingBehavior CommandSource="{x:Type samples:OpenCommand}" CommandTarget="{Binding OpenCommand}"/>
    <toms:CommandRoutingBehavior CommandSource="{x:Type samples:CloseCommand}" CommandTarget="{Binding CloseCommand}"/>
    <toms:CommandRoutingBehavior CommandSource="{x:Type samples:CutCommand}" CommandTarget="{Binding CutCommand}"/>
    <toms:CommandRoutingBehavior CommandSource="{x:Type samples:CopyCommand}" CommandTarget="{Binding CopyCommand}"/>
    <toms:CommandRoutingBehavior CommandSource="{x:Type samples:PasteCommand}" CommandTarget="{Binding PasteCommand}"/>
    <toms:CommandRoutingBehavior CommandSource="{x:Type samples:DeleteCommand}" CommandTarget="{Binding DeleteCommand}"/>
  </i:Interaction.Behaviors>
</UserControl>
